package com.shujia.spark.core

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object Demo3Map {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf()
    conf.setAppName("map")
    conf.setMaster("local")

    val sc = new SparkContext(conf)


    //读取学生表的数据
    val studentsRDD: RDD[String] = sc.textFile("data/students.txt")

    /**
     * map:将rdd的数据一条一条传递给后面的函数，函数的返回值构建成一个新的RDD
     * map算子不会改变总的数据行数
     *
     */

    val clazzRDD: RDD[String] = studentsRDD.map((student: String) => student.split(",").last)

    clazzRDD.foreach(println)

  }

}
